package org.grayrabbit.cms.service.search.impl;

import java.util.Map;

import java.util.Hashtable;

import org.apache.commons.lang.xwork.StringUtils;
import org.grayrabbit.cms.entity.Keywords;


public class KeywordsContext {
	
	private static Map<String,Keywords> keywordsMapById;
	
	public static boolean UPDATE_FLAG = true;	//更新标识
	
	public static boolean isUpdate(){
		return UPDATE_FLAG || keywordsMapById.isEmpty() ;
	}
	
	/**
	 * 应用级内存化信息
	 * @param dictionary
	 */
	public static void put(Keywords keywords){
		if(keywords!=null){
			if(keywordsMapById==null){
				keywordsMapById = new Hashtable<String, Keywords>();
			}
			keywordsMapById.put(keywords.getKeywordsId(), keywords);
		}
	}
	
	/**
	 * 删除
	 * @param dictionary
	 */
	public static void delete(String id){
		if(StringUtils.isNotBlank(id)){
			keywordsMapById.remove(id);
		}
	}
	
	/**
	 * 根据ID获取关键字 
	 * @param id
	 * @return
	 */
	public static Keywords getKeywordsById(String id){
		return keywordsMapById.get(id);
	}
	
	public static void remove(){
		if(keywordsMapById!=null){
			keywordsMapById.clear();
		}
	}

}
